import { getlist, addexam, delexam, addtopic } from '@/api/exam'
export default {
  namespaced: true,
  state: {
    list: [],
    currentpage: 1,
    pageSize: 10,
    total: 0,
    topic: []
  },

  mutations: {
    GET_EXAM(state, res) {
      state.list = res.data
      state.total = res.total
    },
    GET_CURRENTPAGE(state, res) {
      state.currentpage = res
    },
    GET_PAGESIZE(state, res) {
      state.pageSize = res
    },
    GET_TOPIC(state, res) {
      state.topic = res.data
      // console.log(res)
    }
  },

  actions: {
    async getexam({ state, commit }, serch) {
      let obj = {
        currentpage: state.currentpage - 1,
        pageSize: state.pageSize
      }
      if (serch) {
        obj.serch = serch
      }
      let r = await getlist(obj)
      commit("GET_EXAM", r)
    },
    //新增
    addexams({ commit }, form) {
      addexam(form)
    },
    //删除
    delexam({ commit }, id) {
      delexam(id)
    },
    //考试模式获取题
    async getaddtopic({ commit }) {
      let r = await addtopic()
      commit('GET_TOPIC', r)
    }
  },

  getters: {

  }
}